<?php

use yii\helpers\Html;
use yii\helpers\Url;
// use yii\grid\GridView;
use kartik\grid\GridView;
use yii\widgets\Pjax;
/* @var $this yii\web\View */
/* @var $searchModel frontend\models\CountrySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Countries';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="country-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('Create Country', ['create'], ['class' => 'btn btn-success']) ?>
    </p>
    
<?php 
$jsUrl = Url::toRoute(["country/orders","test"=>1]);

//自定义点击触发请求，并且设置了url
$js = <<<JS
$(document).pjax("#update","#testid222",{
    url:"$jsUrl"
});
JS;

$js = <<<JS
    $("body").on("click","#update",function(){
    $.pjax({url:"$jsUrl",
        container:"#testid222",
        pushRedirect:false,
        replaceRedirect:false,
        replace:false,
        push:false});
    })
JS;

$this->registerJs($js);

echo $jsUrl;

//使用下面两选项的话可以使用ajax
// Pjax::begin([
//     // 'counter' => 11,
//     'options'=>['id'=>'testid'],
//     'enablePushState' => false, // to disable push state
//     'enableReplaceState' => false // to disable replace state
//     ]); 
// ?>

<?= Html::a("update", ['country/orders'], ['class' => 'btn btn-lg btn-success','id'=>"update2",'data'=>['pjax'=>"0",],]) ?>
<?= Html::button("update", ['class' => 'btn btn-lg btn-success','id'=>"update"]) ?>

<?php 
$gridColumns = [
            // 序号
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'name',
            'code',
            ['class'=>'\kartik\grid\DataColumn',
             'attribute'=>'code',
            ],
            ['class'=>'kartik\grid\EditableColumn',//可编辑区域的
             'attribute'=>'code',
             'editableOptions'=> function($model,$key,$index){
                return [
                    'header'=>'Name',
                    'size'=>'md',
                    'formOptions'=>['action'=>Url::toRoute(['/country/code'])],
                    // 'asPopover'=>false,
                    // 'afterInput'=>function($form,$widget) use ($model,$index){
                    //     return $form->field($model, "code")->textInput([]);
                    // },
                ];
             }
            ],

            // 下面是操作区域的
            ['class' => 'yii\grid\ActionColumn'],
        ];

echo GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => $gridColumns,
        'pjax'=>true,
        'pjax'=>[
            'neverTimeout'=>true,
            'beforeGrid'=>'my fancy content before',
            'afterGrid'=>'my fancy content after',
        ],
        'resizableColumns'=>true,
        // 'showPageSummary'=>true,
    ]); ?>
<?php //Pjax::end(); ?>



<!-- <div id="testid222"  data-pjax-container="" data-pjax-timeout="1000">
</div> -->

<?php Pjax::begin([
    'options' => ['id' => 'testid222'],
    'enablePushState' => false, // to disable push state
    'enableReplaceState' => false, // to disable replace state
]);?>

<?php Pjax::end();?>

</div>